﻿@using Microsoft.AspNet.Identity
@using QBWeb.Models
@if (Request.IsAuthenticated)
{
    using (Html.BeginForm("LogOff", "Account", FormMethod.Post, new { id = "logoutForm", @class = "navbar-right" }))
    {
        @Html.AntiForgeryToken()

        var db = new QBDbContext();
        var userName = db.UserNameTbs.Find(User.Identity.GetUserId());
        if (userName != null)
        {


            <ul class="nav navbar-nav navbar-right">
                <li>
                    <img src="#" alt="welcome" id="timePic" style="width: 25px; height: 25px; margin-top: 12px"/>
                </li>
                <li >
                    <a href="#" style=" padding-left: 0; padding-right: 0">
                        <span id="showWelcome"></span>
                    </a>
                </li>
                <li>
                    <a href="#" data-toggle="dropdown" class="dropdown-toggle">@userName.NickName<b class="caret"></b></a>
                    <ul class="dropdown-menu">
                        <li><a href="/Manage"><span class="layui-icon layui-icon-username"></span>&ensp;个人中心</a> 
                           @* @Html.ActionLink("个人中心", "Index", "Manage", routeValues: null, htmlAttributes: new { title = "Manage" })*@
                        </li>
                        <li> <a href="javascript:document.getElementById('logoutForm').submit()"><span class="layui-icon layui-icon-logout"></span>&ensp;注销</a></li>    
                    </ul>
                </li>
            </ul>

            <script type="text/javascript">
                showPic();
                function showPic() {
                    const date = new Date();
                    const h = date.getHours();

                    if (h <= 12) {
                        $("#timePic").attr("src", "/img/morning.jpg");
                        document.getElementById("showWelcome").innerHTML = "早上好！" ;
                    }
                    else if (h < 18) {
                        $("#timePic").attr("src", "/img/morning.jpg");
                        document.getElementById("showWelcome").innerHTML = "下午好！";
                    }
                    else if (h > 18) {
                        $("#timePic").attr("src", "/img/evening.jpg");
                        document.getElementById("showWelcome").innerHTML = "晚上好！";
                    }
                }
            </script>
        }
    }
}
else
{
    <ul class="nav navbar-nav navbar-right">
        <li>@Html.ActionLink("注册", "Register", "Account", routeValues: null, htmlAttributes: new { id = "registerLink" })</li>
        <li>@Html.ActionLink("登录", "Login", "Account", routeValues: null, htmlAttributes: new { id = "loginLink" })</li>
    </ul>
}
